﻿@model GPS.ENTITYS.CrudModelDDTTN_QD

@{
    ViewBag.Title = "Sửa quyết định tốt nghiệp";
}

@using (Html.BeginForm("Edit", "GPS_QuyetDinhTotNghiep", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <h3 class="text-center fdb-title-search-form">Sửa quyết định tốt nghiệp</h3>
    <div id="tabs">
        <div id="tabs-1">
            @Html.Hidden("IsEdit", 0)
            @Html.HiddenFor(model => model.ID)
            <label style="color:red">@ViewBag.ErrorDate</label>
            <fieldset class="fs_body">
                <legend class="head_title">Thông tin chi tiết quyết định tốt nghiệp</legend>

                <div class="row margin-top-05">
                    <div class="col-md-2 control-label text-left">
                        Đơn vị đào tạo <span style="color:red">(*)</span>
                    </div>
                    <div class="col-md-4">
                        @Html.DropDownListFor(model => model.DDTTN_QD_DVGTVT_MA, (SelectList)ViewBag.DVGTVT_MAs, new { @class = "form-control", @id = "ddlDVGTVT_MA" })
                        @Html.ValidationMessageFor(model => model.DDTTN_QD_DVGTVT_MA)
                    </div>

                    <div class="col-md-2 control-label text-left">
                        Số quyết định <span style="color:red">(*)</span>
                    </div>
                    <div class="col-md-4">
                        @Html.TextBoxFor(model => model.DDTTN_QD_SO_QD, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.DDTTN_QD_SO_QD)
                    </div>
                </div>

                <div class="row margin-top-05">
                    <div class="col-md-2 control-label text-left">
                        Ngày quyết định <span style="color:red">(*)</span>
                    </div>
                    <div class="col-md-4">
                        @Html.TextBoxFor(model => model.DDTTN_QD_NGAY_QD, "{0:dd/MM/yyyy}", new { @class = "form-control", @style = "width:120px" })

                        @Html.ValidationMessageFor(model => model.DDTTN_QD_NGAY_QD)
                    </div>
                    <div class="col-md-2 control-label">
                        Tên khóa TN <span style="color:red">(*)</span>
                    </div>
                    <div class="col-md-4">
                        @Html.TextBoxFor(model => model.DDTTN_QD_TENKHOA, new { @class = "form-control" })
                        @*@Html.DropDownListFor(model => model.DDTTN_QD_TENKHOA, (SelectList)ViewBag.KH_MAs, string.Empty, new { @class = "form-control", @id = "ddlKH_MA" })*@
                        @Html.ValidationMessageFor(model => model.DDTTN_QD_TENKHOA)
                    </div>

                </div>
                <div class="row margin-top-05">
                    <div class="col-md-2 control-label text-left">
                        Ngày thi dự kiến <span style="color:red">(*)</span>
                    </div>
                    <div class="col-md-4">
                        @Html.TextBoxFor(model => model.DDTTN_QD_NGAY_THI_TN, "{0:dd/MM/yyyy}", new { @class = "form-control", @style = "width:120px" })

                        @Html.ValidationMessageFor(model => model.DDTTN_QD_NGAY_THI_TN)
                    </div>
                    <div class="col-md-2 control-label">
                        Trạng thái
                    </div>
                    <div class="col-md-4">
                        @Html.DropDownListFor(model => model.DDTTN_QD_TT, new List<SelectListItem>
                                {                   new SelectListItem() {Text = "Đã phê duyệt", Value="1"},
                                                    new SelectListItem() {Text = "Chưa phê duyệt", Value="0"}
                                }, new { @class = "form-control" })
                    </div>

                </div>

            </fieldset>
            <fieldset class="fdb-scheduler-border">
                <legend class="fdb-scheduler-border">Thông tin hội đồng</legend>
                <div class="form-group">
                    <div class="col-md-14">
                        <label id="lblValidateDETAIL" style="color: #b94a48"></label>

                        <table class="table table-hover table-bordered table-condensed table-responsive" id="Table1">

                            <tr>
                                <th style="text-align:center; width:300px">
                                    Sát hạch viên
                                </th>
                                <th style="text-align: center; width: 300px">
                                    Hình ảnh
                                </th>
                                <th style="text-align: center; width: 300px">
                                    Chức vụ trong hội đồng thi tốt nghiệp
                                </th>

                                <th valign="middle" style="text-align: center; width: 100px">
                                    <label class="BtnPlus" style="cursor:pointer"><img src="@Url.Content("~/fonts/button-add-icon.png")" title="Thêm mới" /></label>

                                </th>

                            </tr>

                            @{

    int i = 1;
    string lblID = "";

    if (Model.ListDDTTN_HDs != null && Model.ListDDTTN_HDs.Count > 0)
    {
        GPS.DataAccessLayer.DbContextHelper<GPS.DataAccessLayer.GPS_NVContext> _db = GPS.COMMON.Singleton<GPS.DataAccessLayer.DbContextHelper<GPS.DataAccessLayer.GPS_NVContext>>.Inst;
        List<GPS.DataAccessLayer.DGV> lstDGVs = _db.Filter<GPS.DataAccessLayer.DGV>(o => o.GV_DVGTVT_MA == Model.DDTTN_QD_DVGTVT_MA);
        List<GPS.DataAccessLayer.SCVSHV> lstCVSHs = _db.GetAll<GPS.DataAccessLayer.SCVSHV>();

        foreach (var item in Model.ListDDTTN_HDs)
        {

            lblID = "lblDetail_" + i.ToString();
            <tr>
                <td>
                    <select style="text-align: center; width: 250px" name="ddlDTTN_HD_SHV_MA_@i.ToString()" id="ddlDTTN_HD_SHV_MA_@i.ToString()">
                        @foreach (var itemDM in lstDGVs)
                        {
                            <option value="@itemDM.GV_MA" @(itemDM.GV_MA == item.DTTN_HD_SHV_MA ? "selected" : "")>@(itemDM.GV_HODEM + " " + itemDM.GV_TEN)</option>
                        }

                    </select>
                </td>
                <td>
                    
                    @{

                        var _gv = _db.GetOne<GPS.DataAccessLayer.DGV>(o => o.GV_MA == item.DTTN_HD_SHV_MA);

                        String img64Url = string.Empty;
                        if (_gv.GV_ANHCD != null)
                        {
                            String img64 = Convert.ToBase64String(_gv.GV_ANHCD);
                            img64Url = string.Format("data:image/" + _gv.GV_ANHCD + ";base64,{0}", img64);
                        }
                    }
                    <img src="@img64Url" width="50" height="50" />
                 </td>
                <td>
                    <select style="text-align: center; width: 250px" name="ddlDTTN_HD_CVSHV_MA_@i.ToString()" id="ddlDTTN_HD_CVSHV_MA_@i.ToString()">
                        @foreach (var itemDM in lstCVSHs)
                        {
                            <option value="@itemDM.CVSHV_MA" @(itemDM.CVSHV_MA == item.DTTN_HD_CVSHV_MA ? "selected" : "")>@(itemDM.CVSHV_TEN)</option>
                        }

                    </select>
                </td>

                <td style="text-align: center; width: 100px">
                    <label class="BtnPlus" style="cursor:pointer;text-align: center"><img src="@Url.Content("~/fonts/button-add-icon.png")" title="Thêm mới" /></label>
                    <label class="BtnMinus" id="@lblID" style="cursor:pointer"><img src="@Url.Content("~/fonts/DELETE.GIF")" title="Xóa" /></label>
                </td>
            </tr>
                        i++;
        }

        ViewBag.sMaxID = i;
    }
                            }
                            @Html.Raw(@ViewBag.sEditHTML)

                        </table>
                    </div>
                    <div class="col-md-push-4"></div>
                </div>
            </fieldset>
        </div>
    </div>
    <br />
    <div class="row">
        <div class="col-md-12">
            <button type="submit" class="btn btn-danger btn-sm">
                <span class="glyphicon glyphicon-floppy-disk"></span> Cập nhật
            </button>
            &nbsp;&nbsp;
            @Html.ActionLink("Quay lại", "Index", null, new { @class = "btn btn-primary btn-sm" })
        </div>
    </div>
}

<input id="txtDGV" style="display:none" value="@ViewBag.DGVs" />
<input id="txtCVSH" style="display:none" value="@ViewBag.CVSHs" />
<label id="lblID" style="display:none">@ViewBag.sMaxID </label>

<link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="~/Scripts/locales/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

<script src="~/Scripts/datepicker.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
<script src="~/Scripts/jquery.maskedinput.js"></script>
<script src="~/Scripts/jquery.maskMoney.js"></script>
<script src="~/Scripts/jquery.number.js"></script>
<script src="~/Scripts/jquery.masknumber.js"></script>
<script src="~/Scripts/moment.js"></script>


<script type="text/javascript">
    // Voi jQuery 1.9 > thi chi validate gia tri trong active tab
    // Muon validate nhung gia tri trong cac tab khac nua thi dung jquery.validate 1.8.1 or 1.7
    // mask edit cho truong ngay thang (su dung jquery.maskedinput)
    function ToJavaScriptDate(value) {
        if (value != null) {
            var pattern = /Date\(([^)]+)\)/;
            var results = pattern.exec(value);
            var dt = new Date(parseFloat(results[1]));
            return dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear();
        }
        return null;
    }
</script>
<script type="text/javascript">


    $("#DDTTN_QD_NGAY_QD").datepicker({
        changeMonth: true,
        changeYear: true,

        dateFormat: 'dd/mm/yy'
    });
    $("#DDTTN_QD_NGAY_QD").mask("99/99/9999", { placeholder: "dd/mm/yyyy" });

    $("#DDTTN_QD_NGAY_THI_TN").datepicker({
        changeMonth: true,
        changeYear: true,

        dateFormat: 'dd/mm/yy'
    });
    $("#DDTTN_QD_NGAY_THI_TN").mask("99/99/9999", { placeholder: "dd/mm/yyyy" });


    $(function () {
        $(document).tooltip();
    });

</script>

@Styles.Render("~/Content/themes/base/css")

@section scripts
{
    @Scripts.Render("~/Scripts/select2.js")
}



<script type="text/javascript">
    $(document).ready(function () {
        var lblID = "lblDetail_1";
        var ID = 1;

        if ($('#lblID').html().trim() != "") {
            ID = parseInt($('#lblID').html().toString());
        }

        var strDGVs = $('#txtDGV').val();
        var strDGVs = strDGVs + '</select>';

        var strCVSHs = $('#txtCVSH').val();
        var strCVSHs = strCVSHs + '</select>';

        function addRow() {
            var html =
                '<tr >' +
                    '<td ><select style="text-align: center; width: 250px" class="selectSHV_MA"  name="ddlDTTN_HD_SHV_MA_' + ID + '"  id="ddlDTTN_HD_SHV_MA_' + ID + '">' + strDGVs + '</td>' +
                    '<td ><img src="" id="imgGV_ANHCD_' + ID + '" width="50" height="50"/></td>' +
                    '<td ><select style="text-align: center; width: 250px"  name="ddlDTTN_HD_CVSHV_MA_' + ID + '"  id="ddlDTTN_HD_CVSHV_MA_' + ID + '">' + strCVSHs + '</td>' +

                    '<td style="text-align: center; width: 100px"> <label class="BtnPlus" style="cursor:pointer;text-align: center" ><img src="@Url.Content("~/fonts/button-add-icon.png")" title="Thêm mới" /></label>' +
                    ' <label class="BtnMinus" id="lblDetail_' + ID + '" style="cursor:pointer"><img src="@Url.Content("~/fonts/DELETE.GIF")" title="Xóa"  /></label>' +
                    '</td>' +
                '</tr>'
            $(html).appendTo($("#Table1"));

            ID++;

        };
        $("#Table1").on("click", ".BtnPlus", addRow);

        $("#Table1").on("click", ".BtnMinus", deleteRow);


        function deleteRow() {
            lblID = $(this).attr('id');
            lblID = "#" + lblID.toString().trim();
            if (confirm("Bạn chắc chắn muốn xóa?")) {
                var par = $(this).parent().parent();
                par.remove();
            }

            return false;

        };


        $(document).on('change', ".selectSHV_MA", function () {
            // alert($(this).val());
            var gv_ma = $(this).val();
            var thisID = $(this).attr('id');
            var lastNumber = thisID.split('_');
            var imgID = 'imgGV_ANHCD_' + lastNumber[lastNumber.length - 1].toString();
            $.ajax({
                url: '@Url.Action("GPS_IMG_GV", "GPS_QuyetDinhTotNghiep")',
                data: { 'gv_ma': gv_ma },
                type: "post",
                cache: false,
                error: function () {
                    alert("Server access failure!");
                },
                success: function (data) {

                    if (data != null && data.gvs != null && data.gvs.length > 0) {

                        $("#" + imgID).attr("src", "data:image/jpg;base64," + data.gvs[0].GV_ANHCDSTRING);

                    }


                }
            });

        });

    });
</script>
